package com.zlkj.pro.modular.app.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.alibaba.fastjson.JSON;
import com.zlkj.pro.modular.admin.model.vo.UserVO;
import com.zlkj.pro.modular.app.service.AppCustomerService;
import com.zlkj.pro.modular.business.model.dto.CustomerDTO;
import com.zlkj.pro.modular.business.model.vo.CustomerVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.zlkj.pro.core.consts.ProjectConstants.SERVICE_APP_PREFIX;

/**
 * @author liyang
 * @date 2024/4/6
 * @time 14:34
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@ApiResource(name = "客户信息", path = SERVICE_APP_PREFIX + "/customer/info")
public class AppCustomerController {

    private final AppCustomerService appCustomerService;

    @GetResource(name = "客户列表", path = "/findList")
    public ResponseData findList(CustomerDTO dto) {
        List<CustomerVO> restData = appCustomerService.findList(dto);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "经理下级员工列表", path = "/findSubordinateList")
    public ResponseData findSubordinateList(Long userId,String query) {
        List<UserVO> restData = appCustomerService.findSubordinateList(userId, query);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "删除", path = "/delete")
    public ResponseData delete(@RequestBody CustomerDTO dto) {
        boolean restData = appCustomerService.delete(dto);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "查询详情", path = "/findDetail")
    public ResponseData findDetail(CustomerDTO dto) {
        CustomerVO restData = appCustomerService.findDetail(dto);
        return new SuccessResponseData(restData);
    }


    @PostResource(name = "添加", path = "/add")
    public ResponseData add(@RequestBody CustomerDTO dto) {
        log.info("app添加客户参数【{}】", JSON.toJSONString(dto));
        boolean restData = appCustomerService.add(dto);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "编辑", path = "/edit")
    public ResponseData edit(@RequestBody CustomerDTO dto) {
        boolean restData = appCustomerService.edit(dto);
        return new SuccessResponseData(restData);
    }


    @PostResource(name = "添加", path = "/addPro")
    public ResponseData addPro(@RequestBody CustomerDTO dto) {
        log.info("app添加客户参数【{}】", JSON.toJSONString(dto));
        boolean restData = appCustomerService.addPro(dto);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "编辑", path = "/editPro")
    public ResponseData editPro(@RequestBody CustomerDTO dto) {
        boolean restData = appCustomerService.editPro(dto);
        return new SuccessResponseData(restData);
    }


    @GetResource(name = "查询客户分类", path = "/findClassifyList")
    public ResponseData findClassifyList() {
        List<String> restData = appCustomerService.findClassifyList();
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "查询省市区", path = "/findArea")
    public ResponseData findArea(String parentId) {
        List<Map<String, String>> restData = appCustomerService.findArea(parentId);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "补全省市区地址", path = "/fixAddress", requiredLogin = false, requiredPermission = false)
    public ResponseData fixAddress(String type) {
        // type = 1 补全省市区
        // type = 2 移除省市区名称 其他批量截取到备注
        // type = 3 批量更新所在地址
        appCustomerService.fixAddress(type);
        return new SuccessResponseData(null);
    }

}
